"""
copy from oss.common.errors
"""


class LogicError(Exception):
    """程序内部逻辑错误"""

    code = None
    message = None

    def __init__(self, message=None):
        if message:
            self.message = message  # 发生异常时需要传回前端的自定义信息

    def __str__(self):
        return self.code


def gen_error(err_code, message):
    base_cls = (LogicError,)
    cls_attr = {"code": err_code, "message": message}
    return type(err_code, base_cls, cls_attr)


# 客户端错误
AuthFailure = gen_error("AuthFailure", "登录失败")
InvalidParameter = gen_error("InvalidParameter", "URL参数不合法、不存在、值类型错误等")
InvalidAction = gen_error("InvalidAction", "操作不合法")
InvalidUser = gen_error("InvalidUser", "失效的用户")
InvalidToken = gen_error("InvalidToken", "失效的Token")
InvalidParameterValue = gen_error("InvalidParameterValue", "参数的值过期、无效、不能使用")
UnauthorizedUser = gen_error("UnauthorizedUser", "黑名单用户、被禁止操作的用户")
ActionFailure = gen_error("ActionFailure", "操作失败")
NotConfirmError = gen_error("NotConfirmError", "数据未确认")

# 服务端错误
InternalFailure = gen_error("InternalFailure", "各类未知异常")

# 调用服务错误
SendCodeFailure = gen_error("SendCodeFailure", "获取验证码失败")
CreateFlowFailure = gen_error("CreateFlowFailure", "创建流程失败")

# 频率限制问题
LimitAction = gen_error("LimitAction", "访问频率过多")
ObjectHasExistError = gen_error("ObjectHasExistError", "对象已存在")
